//
//  MenuDetailViewController.m
//  Products_B
//
//  Created by lanou on 16/5/30.
//  Copyright © 2016年 朋学友. All rights reserved.
//

//http://api.izhangchu.com/?appVersion=4.4&sysVersion=9.0.2&devModel=iPhone
//material_id=2&methodName=MaterialDishes&page=1&size=6&token=0&user_id=0&version=4.4
#import "MenuDetailViewController.h"
#import "MenuFirstModel.h"
#import "MenuFirstTableViewCell.h"
#import "MenuBigTableViewCell.h"
#import "MenuTwoTableViewCell.h"
#import "MenuThreeTableViewCell.h"
#import "MenuFourTableViewCell.h"
#import <AVFoundation/AVFoundation.h>
#import "MenuFirstDetailViewController.h"
#define kMenuDetailUrl @"http://api.izhangchu.com/"
@interface MenuDetailViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong)UIImageView *PicImaqgeView;
@property (nonatomic, strong)UIView *bigView;

@property (nonatomic, strong)UIButton *button1;
@property (nonatomic, strong)UIButton *button2;
@property (nonatomic, strong)UIButton *button3;
@property (nonatomic, strong)UIButton *button4;

@property (nonatomic, strong)UIView *lineView;
@property (nonatomic, strong)UIScrollView *scrollView;

//@property (nonatomic, strong)UIView *myView1;
//@property (nonatomic, strong)UIView *myView2;
//@property (nonatomic, strong)UIView *myView3;
//@property (nonatomic, strong)UIView *myView4;

@property (nonatomic, strong)UITableView *tableView1;
@property (nonatomic, strong)UITableView *tableView2;
@property (nonatomic, strong)UITableView *tableView3;
@property (nonatomic, strong)UITableView *tableView4;

@property (nonatomic, strong)UIButton *backButton;
@property (nonatomic, strong)UIButton *wujiaoxingButton;
@property (nonatomic, strong)UIButton *backButton1;
@property (nonatomic, strong)UIButton *wujiaoxingButton1;

@property (nonatomic, strong)UITableView *bigTableView;

@property (nonatomic, strong)NSMutableArray *fistModelArray;
@property (nonatomic, assign)NSInteger index;
@property (nonatomic, assign)NSInteger subIndez;
@property (nonatomic, strong)NSMutableDictionary *parDic;
@property (nonatomic, strong)NSMutableDictionary *selectParDic;
@property (nonatomic, strong)NSString *page;
@property (nonatomic, strong)UIView *navView;
@property (nonatomic, assign)CGFloat lastContentOffsetY;

@property (nonatomic, strong)NSString *fourContentString;
@property (nonatomic, strong)NSString *fourPicString;
@property (nonatomic, strong)NSString *threeContentString;
@property (nonatomic, strong)NSString *threePicString;
@property (nonatomic, strong)NSString *twoContentString;
@property (nonatomic, strong)NSString *twoPicString;


@property (nonatomic, strong)NSString *videoString;
@property (nonatomic, strong)AVPlayer *palyer;

@property (nonatomic, assign)CGFloat height;
@property (nonatomic ,strong)NSString *dishes_id;
@end

@implementation MenuDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    
    
   
    
    
    
    self.page = @"1";
    self.parDic = [@{@"material_id":self.idString,@"methodName":@"MaterialDishes",@"page":self.page,@"size":@"6",@"token":@"0",@"user_id":@"0",@"version":@"4.4"}mutableCopy];
    self.selectParDic = [@{@"material_id":self.idString,@"methodName":@"MaterialView",@"token":@"0",@"user_id":@"0",@"version":@"4.4"}mutableCopy];
    
    //    刚进来的时候请求数据
    [self requestData];
    
    [self requestMoreData];
    
    self.fistModelArray = [NSMutableArray array];
//    self.navigationController.navigationBar.translucent = NO;
//    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    self.bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 190)];
//    [self.view addSubview:_bigView];
 
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self addImageView];
    //  创建大的tableView
    self.bigTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    self.bigTableView.delegate = self;
    self.bigTableView.dataSource = self;
    [self.bigTableView registerClass:[MenuBigTableViewCell class] forCellReuseIdentifier:@"MenuBigTableViewCell"];
    self.bigTableView.tableHeaderView = _PicImaqgeView;
    [self.view addSubview:_bigTableView];
    
    
    
    _backButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _backButton.frame = CGRectMake(20, 30, 30, 30);
//    [_backButton setTitle:@"<--" forState:(UIControlStateNormal)];
    [_backButton setBackgroundImage:[UIImage imageNamed:@"menuBack"] forState:(UIControlStateNormal)];
    [_backButton addTarget: self action:@selector(backButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:_backButton];
    _wujiaoxingButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _wujiaoxingButton.frame = CGRectMake(kWidth - 20 - 30, 30, 30, 30);
//    [_wujiaoxingButton setTitle:@"五" forState:(UIControlStateNormal)];
    [_wujiaoxingButton setBackgroundImage:[UIImage imageNamed:@"menuwujiaoxing"] forState:(UIControlStateNormal)];
    [_wujiaoxingButton addTarget:self action:@selector(wujiaoxingButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:_wujiaoxingButton];
    
    self.navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 70)];
    self.navView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_navView];
    _backButton1 = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _backButton1.frame = CGRectMake(20, 30, 30, 30);
    //    [_backButton setTitle:@"<--" forState:(UIControlStateNormal)];
    [_backButton1 setBackgroundImage:[UIImage imageNamed:@"menuBack"] forState:(UIControlStateNormal)];
    [_backButton1 addTarget: self action:@selector(backButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.navView addSubview:_backButton1];
    _wujiaoxingButton1 = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _wujiaoxingButton1.frame = CGRectMake(kWidth - 20 - 30, 30, 30, 30);
    //    [_wujiaoxingButton setTitle:@"五" forState:(UIControlStateNormal)];
    [_wujiaoxingButton1 setBackgroundImage:[UIImage imageNamed:@"menuwujiaoxing"] forState:(UIControlStateNormal)];
    [_wujiaoxingButton1 addTarget:self action:@selector(wujiaoxingButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.navView addSubview:_wujiaoxingButton1];
    self.lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 69, kWidth, 1)];
    self.lineView.backgroundColor = [UIColor grayColor];
    UILabel *titileLabel = [[UILabel alloc]initWithFrame:CGRectMake(kWidth/2 - 30, 30, 60, 30)];
    titileLabel.textAlignment = NSTextAlignmentCenter;
    titileLabel.text = self.text;
    [self.navView addSubview:titileLabel];
    [self.navView addSubview:_lineView];
    self.navView.hidden = YES;
    

    
    

    
    
}
#pragma mark - 请求后面三个数据 -
- (void)requestMoreData{
    [RequestManager requestWithUrl:kMenuDetailUrl requestType:(RequestTypePOST) parDic:self.selectParDic finish:^(NSData *data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        self.fourPicString = jsonDic[@"data"][@"applied_image"];
        self.fourContentString = jsonDic[@"data"][@"applied"];
        [self.bigTableView reloadData];
        self.threeContentString = jsonDic[@"data"][@"effect"];
        self.threePicString = jsonDic[@"data"][@"effect_image"];
        self.twoContentString = jsonDic[@"data"][@"pick"];
        self.twoPicString = jsonDic[@"data"][@"pick_image"];
        
        self.videoString = jsonDic[@"data"][@"video"];
        NSLog(@"%@",self.fourContentString);
        [self.bigTableView reloadData];
        [self.tableView4 reloadData];
    } error:nil];
}
#pragma mark 滚动的代理方法 - 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView == self.scrollView) {
//        NSLog(@"%f",scrollView.contentOffset.y);
//        NSLog(@"1111%f",self.tableView1.contentOffset.y);
//        NSLog(@"2222%f",self.tableView2.contentOffset.y);
        
        
        NSLog(@"2222%f",self.bigTableView.contentOffset.y);
    }
    
    if (scrollView == self.bigTableView) {
        
       
        if (scrollView.contentOffset.y >=80) {
            self.index++;
            self.navView.hidden = NO;
            
            self.bigTableView.frame = CGRectMake(0, 70, kWidth, kHeight-70);
            NSLog(@"%f",scrollView.contentOffset.y);
           
        }else{
            self.index = 0;
        }
        if (self.index == 1) {
            scrollView.contentOffset = CGPointMake(0, 150);
        }
        if (scrollView.contentOffset.y < self.lastContentOffsetY) {
            
            if (scrollView.contentOffset.y <= 80) {
                self.navView.hidden = YES;
                self.bigTableView.frame = CGRectMake(0, 0, kWidth, kHeight);
            }
            
            
        }
        
       
        
        
    }
}
#pragma mark - 刚开始拖拽 -
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    self.lastContentOffsetY = scrollView.contentOffset.y;
}
#pragma mark - 五角星的button
- (void)wujiaoxingButtonAction:(UIButton *)button{
    
}
#pragma mark - 返回按钮的点击方法 - 
- (void)backButtonAction:(UIButton *)button{
    [self.navigationController popViewControllerAnimated:YES];
}
# pragma  mark - 返回tableView行数- 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == self.bigTableView) {
        return 1;
    }
    if (tableView == self.tableView1) {
        return self.fistModelArray.count;
    }
    return 1;
}
#pragma mark - 返回cell - 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.bigTableView) {
        NSLog(@"%f",_height);
        MenuBigTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuBigTableViewCell" forIndexPath:indexPath];
        self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kWidth, self.fistModelArray.count * 120)];
        self.scrollView.contentSize = CGSizeMake(kWidth *4, self.fistModelArray.count * 120);
//            self.scrollView.backgroundColor = [UIColor magentaColor];
        self.scrollView.delegate = self;
        self.scrollView.showsHorizontalScrollIndicator = YES;
        self.scrollView.showsVerticalScrollIndicator = NO;
        self.scrollView.pagingEnabled = YES;
        self.scrollView.bounces = NO;
        self.tableView1 = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, self.fistModelArray.count * 120 ) style:(UITableViewStylePlain)];
//        self.tableView1.backgroundColor = [UIColor yellowColor];
        self.tableView1.bounces = NO;
        [self.scrollView addSubview:_tableView1];
        self.tableView2 = [[UITableView alloc]initWithFrame:CGRectMake(kWidth, 0, kWidth, self.fistModelArray.count * 120) style:(UITableViewStylePlain)];
//        self.tableView2.backgroundColor = [UIColor grayColor];
        [self.scrollView addSubview:_tableView2];
        self.tableView3 = [[UITableView alloc]initWithFrame:CGRectMake(kWidth *2, 0, kWidth, self.fistModelArray.count * 120) style:(UITableViewStylePlain)];

//        self.tableView3.backgroundColor = [UIColor yellowColor];
        [self.scrollView addSubview:_tableView3];
        

        self.tableView4 = [[UITableView alloc]initWithFrame:CGRectMake(kWidth *3, 0, kWidth, self.fistModelArray.count * 120) style:(UITableViewStylePlain)];
//        self.tableView4.backgroundColor = [UIColor magentaColor];
        [self.scrollView addSubview:_tableView4];
        self.tableView2.bounces = NO;
        self.tableView3.bounces = NO;
        self.tableView4.bounces = NO;
        
        self.tableView1.delegate = self;
        self.tableView1.dataSource = self;
        self.tableView4.delegate = self;
        self.tableView4.dataSource = self;
        self.tableView3.delegate = self;
        self.tableView3.dataSource = self;
        self.tableView2.delegate = self;
        self.tableView2.dataSource = self;
        
        self.tableView1.rowHeight = 120;
        [self.tableView1 registerClass:[MenuFirstTableViewCell class] forCellReuseIdentifier:@"MenuFirstTableViewCell"];
        [self.tableView2 registerClass:[MenuTwoTableViewCell class]forCellReuseIdentifier:@"MenuTwoTableViewCell"];
        [self.tableView3 registerClass:[MenuThreeTableViewCell class] forCellReuseIdentifier:@"MenuThreeTableViewCell"];
        [self.tableView4 registerClass:[MenuFourTableViewCell class] forCellReuseIdentifier:@"MenuFourTableViewCell"];
        [cell addSubview:_scrollView];
        
        
            //  上啦加载
        self.bigTableView.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
            if (_scrollView.contentOffset.x == 0) {
            self.page = [NSString stringWithFormat:@"%ld",[self.page integerValue] + 1];
            self.parDic[@"page"] = self.page;
            [self requestData];
            }else{
                [self.bigTableView.mj_footer endRefreshing];
            }
            
        }];
        
        
        
        return cell;
    }
    
    if (tableView == self.tableView1) {
        
        MenuFirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuFirstTableViewCell" forIndexPath:indexPath];
    MenuFirstModel *model = self.fistModelArray[indexPath.row];
        [cell.playButton addTarget:self action:@selector(bofangButton:) forControlEvents:(UIControlEventTouchUpInside)];
        cell.playButton.tag = 1000 + indexPath.row;
    [cell cellConfigureWithModel:model];
        return cell;
    }
   
    if (tableView == self.tableView4) {
        MenuFourTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuFourTableViewCell" forIndexPath:indexPath];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.fourPicString] placeholderImage:nil completed:nil];
        NSLog(@"1111%@",self.fourContentString);
        cell.appliedLabel.numberOfLines = 0;
        cell.appliedLabel.text = self.fourContentString;
        
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
        CGRect bounds = [cell.appliedLabel.text boundingRectWithSize:CGSizeMake(kWidth - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        
        cell.appliedLabel.frame = CGRectMake(10, 140, kWidth - 20, bounds.size.height);
        
        return cell;
    }
    if (tableView == self.tableView3) {
        MenuThreeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuThreeTableViewCell" forIndexPath:indexPath];
        NSLog(@"%@",self.threeContentString);
        cell.effectLabel.text = self.threeContentString;

        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
        CGRect bounds = [cell.effectLabel.text boundingRectWithSize:CGSizeMake(kWidth - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        
        cell.effectLabel.frame = CGRectMake(10, 140, kWidth - 20, bounds.size.height);

        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.threePicString] placeholderImage:nil completed:nil];
        cell.effectLabel.font = [UIFont systemFontOfSize:14];
        cell.effectLabel.textColor = [UIColor grayColor];
        return cell;
    }
    if (tableView == self.tableView2) {
        MenuTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuTwoTableViewCell" forIndexPath:indexPath];
        cell.picklabel.text = self.twoContentString;
//        cell.picklabel.backgroundColor = [UIColor magentaColor];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.twoPicString] placeholderImage:nil completed:nil];
        
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
        CGRect bounds = [cell.picklabel.text boundingRectWithSize:CGSizeMake(kWidth - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];

        cell.picklabel.frame = CGRectMake(10, 140 , kWidth - 20, bounds.size.height);
         NSLog(@"%@",self.fourContentString);
        return cell;
    }
    return nil;
}
#pragma mark - 播放视频的按钮 - 
- (void)bofangButton:(UIButton *)button{
    MenuFirstModel *model = self.fistModelArray[button.tag - 1000];
    
    AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:[NSURL URLWithString:model.video]];
    self.palyer = [[AVPlayer alloc]initWithPlayerItem:item];
    [self.palyer play];
    
    AVPlayerLayer *playerlayer = [AVPlayerLayer playerLayerWithPlayer:self.palyer];
    playerlayer.videoGravity = AVLayerVideoGravityResize;
    playerlayer.frame = CGRectMake(0, 0, kHeight, kWidth);
    playerlayer.backgroundColor = [UIColor blueColor].CGColor;
    [self.view.layer addSublayer:playerlayer];

    
}

#pragma mark - 返回cell 的高度 -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (tableView == self.tableView1) {
        return 120;
    }
    if (tableView == self.tableView4) {
        
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
        CGRect bounds = [self.fourContentString boundingRectWithSize:CGSizeMake(kWidth - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
      CGFloat height = 140 + bounds.size.height + 10;
        
        return height;
    }
    if (tableView == self.bigTableView) {
        
            return self.fistModelArray.count * 120;
        
    }
    if (tableView == self.tableView3) {
        
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
        CGRect bounds = [self.threeContentString boundingRectWithSize:CGSizeMake(kWidth - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        CGFloat height =   bounds.size.height ;
        return height +140 + 10;
        
//         return self.fistModelArray.count *120;
    }
    if (tableView == self.tableView2) {
        
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
        CGRect bounds = [self.twoContentString boundingRectWithSize:CGSizeMake(kWidth - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        CGFloat height = 140 + bounds.size.height + 10;
        return height;
        
//        return self.fistModelArray.count *120;
    }
    return 0;
}
#pragma mark - 点击cell的方法 - 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.tableView1 ) {
        MenuFirstDetailViewController *firstDetailVc = [[MenuFirstDetailViewController alloc]init];
        MenuFirstModel *fistModel = self.fistModelArray[indexPath.row];
        NSLog(@"%@",fistModel.dishes_id);
        firstDetailVc.dishes_id = fistModel.dishes_id;
        [self.navigationController pushViewController:firstDetailVc animated:YES];
    }
}
#pragma mark - 返回区头 - 
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (tableView == self.bigTableView) {
        UIView *TopView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 40)];
        self.button1 = [[UIButton alloc]initWithFrame:CGRectMake(kWidth / 4 *0, 0, kWidth/4, 40)];
        self.button2 = [[UIButton alloc]initWithFrame:CGRectMake(kWidth / 4 *1, 0,kWidth / 4 , 40)];
        self.button3 = [[UIButton alloc]initWithFrame:CGRectMake(kWidth / 4 *2, 0,kWidth / 4 , 40)];
        self.button4 = [[UIButton alloc]initWithFrame:CGRectMake(kWidth / 4 *3, 0,kWidth / 4 , 40)];
        [self.button1 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        self.lineView = [[UIView alloc]initWithFrame:CGRectMake(kWidth / 4 * 0, 38, kWidth/4, 2)];
        self.lineView.backgroundColor = [UIColor orangeColor];
        [TopView addSubview:_lineView];
        
        [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button1 setTitle:@"相关菜例" forState:(UIControlStateNormal)];
        [self.button2 setTitle:@"选购要诀" forState:(UIControlStateNormal)];
        [self.button3 setTitle:@"营养功效" forState:(UIControlStateNormal)];
        [self.button4 setTitle:@"实用百科" forState:(UIControlStateNormal)];
        
        [self.button1 addTarget:self action:@selector(button1Action:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.button2 addTarget:self action:@selector(button2Action:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.button3 addTarget:self action:@selector(button3Action:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.button4 addTarget:self action:@selector(button4Action:) forControlEvents:(UIControlEventTouchUpInside)];
      
        [TopView addSubview:_button1];
        [TopView addSubview:_button2];
        [TopView addSubview:_button3];
        [TopView addSubview:_button4];
        return TopView;
    }
    return nil;
}
#pragma mark - 返回区头的高度 -
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (tableView == self.bigTableView) {
        return 40;
    }
    return 0;
}
#pragma mark - 滚动结束的代理方法 - 
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    
    
    CGFloat index = self.scrollView.contentOffset.x/kWidth;
    if (scrollView == self.scrollView) {
        self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 150);
    
    if (index == 0) {
        [self.button1 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        self.lineView.frame = CGRectMake(kWidth/4*0, 38, kWidth/4, 2);
        [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        self.scrollView.contentOffset = CGPointMake(0, 0);
//        NSLog(@"1 %f",self.tableView1.contentOffset.y);
//        self.tableView1.contentOffset = CGPointMake(0, 0);
        
        
//        self.scrollView.frame = CGRectMake(self.scrollView.frame.origin.x, self.scrollView.frame.origin.y, kWidth, kHeight - 190);
        
    }
    if (index == 1) {
        [self.button2 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        self.lineView.frame = CGRectMake(kWidth/4*1, 38, kWidth/4, 2);
        [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        self.scrollView.contentOffset = CGPointMake(kWidth, 0);
//        NSLog(@"2 %f",self.tableView2.contentOffset.y);
//         self.tableView2.contentOffset = CGPointMake(0, 0);
        
        
//        self.scrollView.frame = CGRectMake(self.scrollView.frame.origin.x, self.scrollView.frame.origin.y, kWidth, kHeight - 190);
    }
    if (index == 2) {
        [self.button3 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        self.lineView.frame = CGRectMake(kWidth/4*2, 38, kWidth/4, 2);
        [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        self.scrollView.contentOffset = CGPointMake(kWidth *2, 0);
//        NSLog(@"3 %f",self.tableView3.contentOffset.y);
//         self.tableView3.contentOffset = CGPointMake(0, 0);
        
        
//        self.scrollView.frame = CGRectMake(self.scrollView.frame.origin.x, self.scrollView.frame.origin.y, kWidth, kHeight - 190);
    }
    if (index == 3) {
        [self.button4 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        self.lineView.frame = CGRectMake(kWidth/4*3, 38, kWidth/4, 2);
        [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        self.scrollView.contentOffset = CGPointMake(kWidth *3, 0);
//         self.tableView4.contentOffset = CGPointMake(0, 0);
        
        
//        self.scrollView.frame = CGRectMake(self.scrollView.frame.origin.x, self.scrollView.frame.origin.y, kWidth, kHeight - 190);
    }
        
        
//        self.scrollView.frame = CGRectMake(self.scrollView.frame.origin.x, self.scrollView.frame.origin.y, kWidth, kHeight);
//        self.tableView1.frame = CGRectMake(0, 0, kWidth, kHeight);
//        self.tableView2.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
//        self.tableView3.frame = CGRectMake(kWidth *2, 0, kWidth, kHeight);
//        self.tableView4.frame = CGRectMake(kWidth *3, 0, kWidth, kHeight);
    }
}

#pragma mark - 当push的时候隐藏tabBar
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}
#pragma mark 4个Button的点击方法 - 
- (void)button1Action:(UIButton *)button{
    [self.button1 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.lineView.frame = CGRectMake(kWidth/4*0, 38, kWidth/4, 2);
    [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    self.scrollView.contentOffset = CGPointMake(0, 0);
    
    
    self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 150);
}
- (void)button2Action:(UIButton *)button{
    [self.button2 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.lineView.frame = CGRectMake(kWidth/4*1, 38, kWidth/4, 2);
    [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
     self.scrollView.contentOffset = CGPointMake(kWidth, 0);
    self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 150);
}
- (void)button3Action:(UIButton *)button{
    [self.button3 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.lineView.frame = CGRectMake(kWidth/4*2, 38, kWidth/4, 2);
    [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
         self.scrollView.contentOffset = CGPointMake(kWidth *2, 0);
    self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 150);
}
- (void)button4Action:(UIButton *)button{
    [self.button4 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.lineView.frame = CGRectMake(kWidth/4*3, 38, kWidth/4, 2);
    [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
          self.scrollView.contentOffset = CGPointMake(kWidth *3, 0);
    self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 150);
}
#pragma mark 添加上面的imageView - 
- (void)addImageView{
    self.PicImaqgeView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 150)];
    self.PicImaqgeView.userInteractionEnabled = YES;
    UIButton *playButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [playButton setBackgroundImage:[UIImage imageNamed:@"menubofang"] forState:(UIControlStateNormal)];
    [playButton addTarget:self action:@selector(PicImaqgeViewTapAction:) forControlEvents:(UIControlEventTouchUpInside)];
    playButton.frame = CGRectMake(kWidth/2 - 15, 150 / 2 - 15, 30, 30);
    [self.PicImaqgeView addSubview:playButton];
//    self.PicImaqgeView.backgroundColor = [UIColor cyanColor];
    UITapGestureRecognizer *PicImageViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(PicImaqgeViewTapAction:)];
    [self.PicImaqgeView addGestureRecognizer:PicImageViewTap];
    UILabel *label= [[UILabel alloc]initWithFrame:CGRectMake(kWidth / 2 - 30, 20, 60, 20)];
    label.text = self.text;
    label.textAlignment = NSTextAlignmentCenter;
    [self.PicImaqgeView addSubview:label];
//    [self.view addSubview:_PicImaqgeView];
}
#pragma mark - 上面imageView 的点击方法 - 
- (void)PicImaqgeViewTapAction:(UITapGestureRecognizer *)tap{
    NSLog(@"%@",self.videoString);
    AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:[NSURL URLWithString:self.videoString]];
    self.palyer = [[AVPlayer alloc]initWithPlayerItem:item];
    [self.palyer play];
    
    AVPlayerLayer *playerlayer = [AVPlayerLayer playerLayerWithPlayer:self.palyer];
    playerlayer.videoGravity = AVLayerVideoGravityResize;
    playerlayer.frame = CGRectMake(0, 0, kHeight, kWidth);
    playerlayer.backgroundColor = [UIColor blueColor].CGColor;
    [self.view.layer addSublayer:playerlayer];
   
    [self.view addSubview:_bigView];
    
}
#pragma mark - 刚进来的时候请求数据 -
- (void)requestData{
    [RequestManager requestWithUrl:@"http://api.izhangchu.com/" requestType:(RequestTypePOST) parDic:self.parDic finish:^(NSData *data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
       NSArray *array = [MenuFirstModel modelConfigureWithDic:jsonDic];
        for (MenuFirstModel *model in array) {
            [self.fistModelArray addObject:model];
        }
        [self.PicImaqgeView sd_setImageWithURL:[NSURL URLWithString:self.imageString] placeholderImage:nil completed:nil];
       
           [self.bigTableView reloadData];
        [self.bigTableView.mj_footer endRefreshing];
        
      
    } error:nil];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
